import os
from channels.auth import AuthMiddlewareStack
from channels.routing import ProtocolTypeRouter, URLRouter
from channels.security.websocket import AllowedHostsOriginValidator
from chat.routing import websocket_urlpatterns
from .middleware import QueryAuthMiddleware
# os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")
application = ProtocolTypeRouter(
    {
        # "websocket": AllowedHostsOriginValidator(
        #     AuthMiddlewareStack(URLRouter(websocket_urlpatterns)) # 默认使用django 用户认证
        #     # QueryAuthMiddleware(URLRouter(websocket_urlpatterns))  # 自定义用户认证
        # ),
        "websocket": 
            QueryAuthMiddleware(URLRouter(websocket_urlpatterns)) # 默认使用django 用户认证
            # QueryAuthMiddleware(URLRouter(websocket_urlpatterns))  # 自定义用户认证
    }
)